<template>
  <view
    v-if="alertShow"
    class="specially_invite_box"
    @click.stop="handleClose"
    @touchstart="touchstart"
    @touchmove="touchstart"
  >
    <view class="specially_invite_inner">
      <image
        mode="scaleToFill"
        :src="alertImg"
        style="width: 100%; height: 100%"
      />
      <view class="specially_invite_hot" @click.stop="handleHotClick()"></view>
      <view class="specially_invite_close" @click.stop="handleClose">
        <img
          style="width: 100%; height: 100%"
          src="https://100000063-1252208446.file.myqcloud.com/images/macallan-remvp/Close_btn_white.png"
        />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      actList: [],
      alertImg: "",
      alertPath: "",
      alertIds: "",
      linkType: "",
      miniOutAppId: "",
      alertShow: false,
      itemEl:{}
    };
  },
  props: {
    jsonData: {
      typeof: Array,
      default: [],
    },
  },
  async mounted() {
    this.initData();
  },
  methods: {
    touchstart() {},
    initData() {
      try {
        const _showLists = getApp().globalData.speciallyInviteShowLists;
        for (let i = 0; i < this.$props.jsonData.length; i++) {
          const el = this.$props.jsonData[i];
          const _str = el.name + el.activityId;
          if (!_showLists.includes(_str)) {
            if (el.jsonData && el.jsonData.isShowState) {
              this.alertImg = el.jsonData.activityLinkImgLink;
              this.alertPath = el.jsonData.activityLink;
              this.linkType = el.jsonData.linkType;
              this.miniOutAppId = el.jsonData.wxId || "";
              this.itemEl = el;
              this.alertIds = _str;
              this.alertShow = true;
            } else {
              getApp().globalData.speciallyInviteShowLists.push(_str);
            }
          }
        }
      } catch (e) {
        console.log("########  speciallyInviteDialog--initData--error", e);
      }
    },
    handleClose() {
      getApp().globalData.speciallyInviteShowLists.push(this.alertIds);
      this.alertShow = false;
      this.alertImg = "";
      this.alertPath = "";
      this.alertIds = "";
      this.initData();
    },
    handleHotClick() {
      try {
        const pages = getCurrentPages();
        const currPage = pages[pages.length - 1];
        const route = currPage.route;
        const params = {
          page_name: "特邀活动",
          gift_name: this.itemEl.name|| '',
          button_name: "即刻报名",
        };
        this.$commonSensors.giftsDetailTrack('GiftsDetailPageClick',params);
        const that = this;
        getApp().globalData.speciallyInviteShowLists.push(this.alertIds);
        //  半屏小程序跳转，半屏方法不能去嵌套在任何方法内调用
        if (this.linkType == "miniOutHalf") {
          //  跳转其他半屏小程序
          uni.openEmbeddedMiniProgram({
            appId: this.miniOutAppId,
            path: "/" + this.alertPath,
            success(res) {},
            fail(res) {},
            complete() {
              that.alertShow = false;
            },
          });
        } else {
          switch (this.linkType) {
            case "miniIn":
              const _path = [
                "pages/item/categoryNew",
                "pages/cart/cart",
                "pages/info/info",
                "pages/exploration/exploration",
              ];
              if (_path.includes(this.alertPath)) {
                uni.redirectTo({
                  url: "/" + this.alertPath,
                  complete() {
                    that.alertShow = false;
                  },
                });
              } else {
                uni.navigateTo({
                  url: "/" + this.alertPath,
                  complete() {
                    that.alertShow = false;
                  },
                });
              }
              break;
            case "miniOut":
              uni.navigateToMiniProgram({
                appId: this.miniOutAppId,
                path: "/" + this.alertPath,
                complete() {
                  that.alertShow = false;
                },
              });
              break;
            case "H5":
              uni.navigateTo({
                url: `/pages/litha-launch/official/official?src=${encodeURIComponent(
                  JSON.stringify(this.alertPath)
                )}`,
                complete() {
                  that.alertShow = false;
                },
              });
              break;
            default:
              break;
          }
        }
      } catch (e) {}
    },
  },
};
</script>

<style lang="scss">
.specially_invite_box {
  background: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999999;
}
.specially_invite_inner {
  position: absolute;
  left: 48rpx;
  top: 50%;
  width: 654rpx;
  height: 1014rpx;
  margin-top: -507rpx;
  image {
    width: 100%;
    height: 100%;
  }
}
.specially_invite_hot {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1999;
  bottom: 0;
  width: 100%;
}
.specially_invite_close {
  width: 64rpx;
  height: 64rpx;
  position: absolute;
  left: 50%;
  margin-left: -32rpx;
  bottom: -96rpx;
  z-index: 1999;
}
</style>
